const { exchange } = require('./index')
const _ = require('lodash')
const moment = require('moment')
const { default: Decimal } = require('_decimal.js@10.2.1@decimal.js')
const log = console.log
const Api = require('./../service/Api')
// // 调试下单
// exchange.fetchBalance()
//     .then(balanceInfo => {
//         const freeAmount = _.get(balanceInfo, 'USDT.free')
//         const totalAmount = _.get(balanceInfo, 'USDT.total')
//         const usedAmount = _.get(balanceInfo, 'USDT.used')
//         const isFree = freeAmount === totalAmount && usedAmount === 0
//         return {
//             isFree, // 是否空仓
//             freeAmount  // 空仓金额
//         }
//     })
// exchange.load_markets()
//     .then(markets => {
//         console.log('markets, BTS/USDT', markets['BTS/USDT'])
    // })
const tick = 'BTC/USDT'
const quantity = 0.001
const orderDirection = 'buy'
const positionSide = orderDirection === 'buy' ? 'LONG' : 'SHORT'
// const otherPositionSide = orderDirection === 'sell' ? 'LONG' : 'SHORT'
// 挂单
this.$exchange = exchange
// console.log('this.$exchange', this.$exchange)
Api.setState({
    exchange,
    tick,
    symbol: 'BTCUSDT',
    exchangeId: 'binance',
    leverage: 76
})

Api.cancelSomeStopOrders()

// Promise.all([
//     this.$exchange.createOrder(tick, 'TAKE_PROFIT', 'sell', quantity, 90000, {
//         'positionSide': positionSide,
//         'stopPrice': 90000
//         // 'closePosition': true
//     }),
//     this.$exchange.createOrder(tick, 'TAKE_PROFIT', 'sell', quantity, 80000, {
//         'positionSide': positionSide,
//         'stopPrice': 80000
//         // 'closePosition': true
//     }),
//     this.$exchange.createOrder(tick, 'TAKE_PROFIT', 'sell', quantity, 70000, {
//         'positionSide': positionSide,
//         'stopPrice': 70000
//         // 'closePosition': true
//     }),this.$exchange.createOrder(tick, 'TAKE_PROFIT', 'sell', quantity, 90000, {
//         'positionSide': positionSide,
//         'stopPrice': 90000
//         // 'closePosition': true
//     }),
//     this.$exchange.createOrder(tick, 'TAKE_PROFIT', 'sell', quantity, 80000, {
//         'positionSide': positionSide,
//         'stopPrice': 80000
//         // 'closePosition': true
//     }),
//     this.$exchange.createOrder(tick, 'TAKE_PROFIT', 'sell', quantity, 70000, {
//         'positionSide': positionSide,
//         'stopPrice': 70000
//         // 'closePosition': true
//     }),this.$exchange.createOrder(tick, 'TAKE_PROFIT', 'sell', quantity, 90000, {
//         'positionSide': positionSide,
//         'stopPrice': 90000
//         // 'closePosition': true
//     }),
//     this.$exchange.createOrder(tick, 'TAKE_PROFIT', 'sell', quantity, 80000, {
//         'positionSide': positionSide,
//         'stopPrice': 80000
//         // 'closePosition': true
//     }),
//     this.$exchange.createOrder(tick, 'TAKE_PROFIT', 'sell', quantity, 70000, {
//         'positionSide': positionSide,
//         'stopPrice': 70000
//         // 'closePosition': true
//     })
// ]).then(orderList => {
//     Api.cancelSomeStopOrders()
// })
